/*******************************************************************************
 * Copyright (c) 2007 University of Oslo.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     University of Oslo - initial API and implementation
 *******************************************************************************/

package com.cea.papyrus.diagram.sequence.sedi.edit;

import org.eclipse.draw2d.IFigure;
import org.eclipse.gef.EditPolicy;
import org.eclipse.uml2.uml.CombinedFragment;
import org.eclipse.uml2.uml.InteractionOperatorKind;

import com.cea.papyrus.core.editor.ModelManager;
import com.cea.papyrus.diagram.sequence.sedi.edit.policy.DeletionEditPolicy;
import com.cea.papyrus.diagram.sequence.sedi.figures.CoregionFigure;
import com.cea.papyrus.diagram.sequence.sedi.model.util.ModelUtil;
import com.cea.papyrus.diagraminterchange2.di2.GraphElement;

/**
 * Edit part for CoRegions.
 * 
 * @author Andreas Limyr
 * @author frankd@ifi.uio.no
 */
public class CoregionEditPart extends SeDiSubpartEditPart {

    public CoregionEditPart(GraphElement model, ModelManager modelManager) {
        super(model, modelManager);
        // model != null guaranteed by superclass
        if (ModelUtil.<CombinedFragment> getSemantic(model).getInteractionOperator().getValue() != InteractionOperatorKind.PAR)
            throw new IllegalArgumentException(model.toString());
    }

    protected IFigure createFigure() {
        return new CoregionFigure();
    }

    protected void createEditPolicies() {
        super.createEditPolicies();
        
        // Add edit policy to handle deletion requests (replace SeDiSubpartEditPolicy)
		installEditPolicy(
				EditPolicy.COMPONENT_ROLE,
		        new DeletionEditPolicy());
    }
}
